package com.niit.session13.error;

public class Girlfriend {
	private String name;
	private int age;

	public Girlfriend(String name, int age){
		super();
		this.name = name;
		if(age>=18 && age <50) {
			this.age = age;
		}else {
//			如果年龄不符合要求，就显式的抛出异常，让外部的类实例化这个类的时候要处理这个异常
			throw new AgeException();
		}
	}

	public Girlfriend() {
		super();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		if(age>=18 && age <50) {
			this.age = age;
		}else {
//			如果抛出的是运行时异常，不需要强制捕获
			throw new RuntimeException();
		}
	}

}
